package se.gtg.einstein;

import java.text.DecimalFormat;
import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

public class ShowResultActivity extends Activity implements OnClickListener{
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.showresult);
		ListView listView = (ListView) findViewById(R.id.listView1);
		Button btnNewSearch = (Button) findViewById(R.id.button1);

		ArrayList<String> list = new ArrayList<String>();
		EcoApp ecoApp = (EcoApp) getApplicationContext();
		SearchLists searchLists = ecoApp.getSearchLists();
		double sumAmount = 0;

		for (SearchList searchList : searchLists.getSearchListsArray()) {
			if (searchList.getSearchListArray().size() > 0) {
				SearchList.SearchRecord searchRecord = searchList.getSearchListArray().get(0);
				sumAmount = sumAmount + searchRecord.getPrice();
				list.add(searchRecord.getPresentation());
			}
		}
		
		DecimalFormat twoDecimals = new DecimalFormat("00.00");
		String stringAmount = twoDecimals.format(sumAmount);
		TextView text = (TextView) findViewById(R.id.textView1);
		text.setText("Summa: " + stringAmount + " Kr");
		int textViewResourceId = android.R.layout.simple_list_item_1;
		ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, textViewResourceId, list);
		listView.setAdapter(arrayAdapter);
		
		btnNewSearch.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		Intent newSearch = new Intent(this,EcoAppActivity.class);
		this.startActivity(newSearch);
	}

}
